7.1. System Output
It is a bit late to mention this now, but we’ve already overlooked a strange and important fact.
⎕ ← “HELLO WORLD”;
HELLO WORLD
Of course, this operation is standard output. What I
want you to focus on is not what standard output is.
However, what is “the statement on the left-side”?
I’m going to explain more details in chapter 12, but
this is actually not a function. AROAPL calls this
procedure as “system output”.
We have already seen three of them: ⎕
(standard output) and ⎕IMPORT (import
modules).
Then, I’ll show the rules of system output below:
- system output is always placed to left-side
- system output has single assignment
- system output cannot influent any constants or user-defined variable values
- system output cannot influent functions
- system output cannot influent operators
- system output can influent state of OS
- programmer cannot make system outputs
Aside from the three examples mentioned above, file system operations are the most effective way to influence the OS. The following sections will introduce these features.
7.2. DateTime Operations
Datetime operations were introduced in Chapter 6, but
they also appear in system output. The only example of
this is the ⎕TIMERS (second timer):
⎕TIMERS ← 3; ⍝ WAIT FOR 3 SECONDS ⍝
7.3. Directory Operations on File System
7.3.1. Check The Existence of Directory
⎕IMPORT ← "FS";
PATH ← "PATH/TO/DIR";
⎕ ← ⎕IF:κ[?] ⟨⎕DEXISTS PATH, "DIRECTORY EXISTS", "DIRECTORY DOES NOT EXIST"⟩;
if directory does not exist:
DIRECTORY DOES NOT EXIST
7.3.2. Create Directory
⎕IMPORT ← "FS";
PATH ← "PATH/TO/DIR";
⎕DCREATE ← PATH;
if directory does not exist:
DIRECTORY DOES NOT EXIST ERROR: PATH/TO/DIR
7.3.3. Move Directory
⎕IMPORT ← "FS";
PATH ← "PATH/TO/DIR";
PATH ← "PATH/TO/DIR2";
⎕DMOVE ← ⟨PATH, PATH2⟩;
DIRECTORY DOES NOT EXIST ERROR: PATH/TO/DIR
7.3.4. Copy Directory
⎕IMPORT ← "FS";
PATH ← "PATH/TO/DIR";
PATH ← "PATH/TO/DIR2";
⎕DCOPY ← ⟨PATH, PATH2⟩;
DIRECTORY DOES NOT EXIST ERROR: PATH/TO/DIR
7.3.5. Rename Directory
⎕IMPORT ← "FS";
PATH ← "PATH/TO/DIR";
PATH ← "PATH/TO/DIR2";
⎕DRENAME ← ⟨PATH, PATH2⟩;
DIRECTORY DOES NOT EXIST ERROR: PATH/TO/DIR
7.3.6. Delete Directory
⎕IMPORT ← "FS";
PATH ← "PATH/TO/DIR";
⎕DDELETE ← PATH;
DIRECTORY DOES NOT EXIST ERROR: PATH/TO/DIR
7.3.7. Search Directories
7.4. File Operations on File System
7.4.1. Check The Existence of File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
⎕ ← ⎕IF:κ[?] ⟨⎕FEXISTS PATH, "FILE EXISTS", "FILE DOES NOT EXIST"⟩;
if file does not exist:
FILE DOES NOT EXIST
7.4.2. Create File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
⎕FCREATE ← PATH;
if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.3. Move File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
PATH2 ← "PATH/TO/FILE2";
⎕FMOVE ← ⟨PATH, PATH2⟩;
if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.4. Copy File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
PATH2 ← "PATH/TO/FILE2";
⎕FCOPY ← ⟨PATH, PATH2⟩;
if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.5. Rename File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
PATH2 ← "PATH/TO/FILE2";
⎕FRENAME ← ⟨PATH, PATH2⟩;
if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.6. Delete File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
⎕FDELETE ← PATH;
if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.7. Search Files
7.4.8. Open Text File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
⎕ ← ⎕FGETT PATH;
if file exists:
text data
hello world
{
"json-data": "json-data"
}
else if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.9. Open Binary File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
⎕ ← ⎕FGETB PATH;
if file exists:
⊤ ⊤ ⊤ ⊥ ⊤ ⊤ ⊤ ⊥ ⊤ ⊤ ⊥ ⊤ ⊤ ⊥ ⊥ ⊤
else if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.10. Overwrite Text File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
TEXT ← "
text data
hello world
{
\"json-data\": \"json-data\"
}
";
⎕FPUTT ← ⟨PATH, TEXT⟩;
else if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.4.11. Overwrite Binary File
⎕IMPORT ← "FS";
PATH ← "PATH/TO/FILE";
BA ← ⊤ ⊤ ⊤ ⊥ ⊤ ⊤ ⊤ ⊥ ⊤ ⊤ ⊥ ⊤ ⊤ ⊥ ⊥ ⊤;
⎕FPUTT ← ⟨PATH, BA⟩;
else if file does not exist:
FILE DOES NOT EXIST ERROR: PATH/TO/FILE
7.5. OS Interaction
You can control OS using CLI (Command Line Interface).
For example, let’s use the ls command to
take a look at the output:
⎕IMPORT ← "OS";
⎕OS ← ⟨"ls -a", φ⟩;
Also, there are cases when you need to provide additional inputs after executing a command. You can use the second argument for this purpose:
⎕IMPORT ← "OS";
⎕OS ← ⟨"apt update", ⟨"y"⟩⟩;
Others, such as running shell scripts, etc.
7.6. Network Programming
However, unfortunately, from a network programming perspective, we only support the HTTP protocol, and even then, only on the client side.
7.6.1. HTTP Client
Once you are able to handle formats such as JSON, you’ll be able to work with REST APIs in server-side programming as well.